#include <Controller.h>
#include <InputEventReceiver.h>

InputEventReceiver *input;

	MouseController::MouseController(DeviceInfo *c){
		this->initController(c);
	}

	MouseController::MouseController(DeviceInfo *c, OptParams o, int length){
		this->initController(c);
		((IrrlichtDevice*)(o.info))->setEventReceiver(input);
	}

	MouseController::~MouseController(){
		input->~InputEventReceiver();
	}

	void MouseController::initController(DeviceInfo *c) const{
		printf("Initialisiere Controller!\n");

		c->cursorXbin = false;
		c->cursorYbin = false;
		c->objectYBin = true;
		c->rotXbin = true;
		c->rotYbin = true;
		c->rotZbin = true;
		c->selectObjectBin = true;
		c->dropObjectBin = true;
		c->endApplicationBin = true;

		input = new InputEventReceiver();

		printf("Controller ist da!\n");
	}

	void MouseController::updateController() const{
		
	}

	void MouseController::drop() const{
		this->~MouseController();
	}

	void MouseController::getRotateX(ActionReturn *a) const{
		if(input->IsKeyJustPressed(irr::KEY_LEFT))
			a->actionOccured = true;
	}

	void MouseController::getRotateY(ActionReturn *a) const{

	}

	void MouseController::getRotateZ(ActionReturn *a) const{

	}

	void MouseController::getRotateGame(ActionReturn *a) const{

	}

	void MouseController::getMoveCursorX(ActionReturn *a) const{
	
	}

	void MouseController::getMoveCursorY(ActionReturn *a) const{
	
	}

	void MouseController::getMoveObjectY(ActionReturn *a) const{
		if(input->IsKeyJustPressed(irr::KEY_UP))
			a->actionOccured = true;
	}

	void MouseController::getSelectObject(ActionReturn *a) const{
		if(input->GetMouseState().LeftButtonDown){
			a->actionOccured = true;
		}
	}

	void MouseController::getDropObject(ActionReturn *a) const{
		if(input->GetMouseState().RightButtonDown){
			a->actionOccured = true;
		}
	}

	void MouseController::getEndApplication(ActionReturn *a) const{
		if(input->IsKeyDown(irr::KEY_ESCAPE))
			a->actionOccured = true;
	}